#ifndef _MOE_OBSERVABLE
#define _MOE_OBSERVABLE

#include "engine/ArrayList.hh"
#include "engine/Observer.hh"

/**The Observable part of the Observer pattern*/
class Observable {

private:
    ArrayList<Observer> *observers;

public:

    Observable() {
        observers = new ArrayList<Observer>(false);
    }

    virtual ~Observable() {
        delete observers;
    }

    virtual void addObserver(Observer *observer) {
        observers->add(observer);
    }

    virtual void removeObserver(Observer *observer) {
        observers->remove(observer);
    }

    virtual void removeObservers() {
        observers->removeAll();
    }

    virtual void notifyObserver(Observer *observer, void *value) {
        observer->notify(value);
    }

    virtual void notifyObservers(const void *value) {
        for (int i = 0; i < observers->length(); i++) observers->get(i)->notify(value);
    }
};

#endif
